﻿var gWPageIndex = 1;
var gWLastCount = 15;

function pageLoad(sender, args) 
{
    if(typeof($get("commentPager")) != "undefined")
    {
        RendPageNavigator(comPage,"commentPager","GetPage");
    }
     
}
function erclose()
{
    if($get("valContent").style.display=="")
    {
        $get("valContent").style.display='none';
    }
}
//添加小黑板信息
function AddComm()
{
    if($get("txtCommInput").value=="")
    {
        $get("valContent").style.display=''; 
        return;
    }
    $get("btnCommInput").disabled=true;
    showProgressBar(true);
    if(Memberno=="")
    {
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+top.location.href;
        return;
    }    
    var con=$get("txtCommInput").value.replace(/<script[^>]*>([\u0001-\uFFFF]*?)<\/script>/gi,"");
    if(con.length>2000) con=con.substring(0,2000);
    WebServices.My.AddGetComment(Memberno,1,gWLastCount,con,onsuccAc);
}
//初始化添加小黑板的数据
function onsuccAc(result)
{
    showProgressBar(false);
    $("btnCommInput").disabled=false;
    if(result!=null&&result[0]==1)
    {
        $("txtCommInput").value="";        
        RendComList(result[1],"CommentList");
        RendPageNavigator(result[2],"commentPage","GetPage");        
    }
    else
    {       
        $get("MessagesBox").style.display='';
        $get("MessageImg").src = MessageImageF;
        $get("MessageText").innerHTML = MessageTextF;
    }
}

//通过页面得到小黑板上面的留言
function GetAllComment(pageIndex,pageCount)
{
    WebServices.My.GetAllComment(Memberno,pageIndex,pageCount,onsucc);
}
//初始化小黑板数据
function onsucc(result)
{
   RendComList(result[1],"CommentList");
   RendPageNavigator(result[0],"commentPager","GetPage");
   showProgressBar(false);
}
//得到页面数据
function GetPage(pageIndex)
{
    gDPageIndex = pageIndex;
    showProgressBar(true);    
    GetAllComment(gDPageIndex,gWLastCount);
}
//替换小黑板上面的信息
function RendComList(list,divID)
{
    var domDiv1 = $get(divID);   
    if(domDiv1!=null)
    {
        if(Sys.UI.DomElement.containsCssClass(domDiv1, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv1, "DisplayNone");
        }
        if($get("CommentTemplate")==null) return;
        var item= $get("CommentTemplate").innerHTML;
        var listBuilder = new Sys.StringBuilder();
        for (var index = 0; index < list.length; ++index) 
        {
            var obj = list[index];
            var tmp = item.replace(/\$Avatar\$/gi,"<img src=\""+(obj.avatar==""?"/Images/No_pic.gif":obj.avatar)+"\"/>");
            tmp = tmp.replace(/\$NickName\$/gi,obj.nickname);
            tmp = tmp.replace(/\$userFrom\$/gi,obj.userFrom);
            tmp = tmp.replace(/\$content\$/gi,obj.content);
            tmp = tmp.replace(/\$tcm2Id\$/gi,obj.tcm2Id);
            tmp = tmp.replace(/\$CreateDate\$/gi,GetFormatDate(gDateFormat,gStrDate2,obj.DiffDate));            
            listBuilder.append(tmp);
        }
        domDiv1.innerHTML = listBuilder.toString();
   }
}
//删除留言
function DelComment(id)
{
    if(Memberno=="")
    {
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+top.location.href;
        return;
    }
    showProgressBar(false,true);
    $("$divIput$").style.display = "none";
    var title = C1008;
    var body="<div class='Popup_button'><input type='button' value='"+C0069+"' id='addOkButton' class='button' onclick=\"CommDelete('"+id+"')\" />&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value='"+gCancel+"' id='addCancelButton' class='buttong' onclick='webFailure()'/></div>";
    var obj = {}
    $ShowMessageBox$(title,body,obj,webFailure,300);
   
}
function CommDelete(id)
{
    WebServices.My.DeleteGetComment(1,gWLastCount,id,onsucc,webFailure);
}
function onsucc(result)
{
    if (result!=null)
    {
        RendComList(result[0],"CommentList");
        RendPageNavigator(result[1],"commentPage","GetPage");
    }
    else
    {        
        $get("MessagesBox").style.display='';
        $get("MessageImg").src = MessageImageF;
        $get("MessageText").innerHTML = MessageTextF;
    }
    $EndMessageBox$();      
    showProgressBar(false);
}
function webFailure()
{
    $EndMessageBox$();
}
 if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();